package com.siwei.mes.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author Administrator
 * @Date 2023/12/5 9:38
 * @Version 1.0
 * @Description 获取登录相关的
 */
@Slf4j
@Service
public class AuthServiceImpl implements AuthService {

    @Override
    public Long getLoginUserId() {
        boolean login = StpUtil.isLogin();
        if (login) {
            return StpUtil.getLoginIdAsLong();
        }
        return null;
    }

    @Override
    public String getLoginUserName() {
        boolean login = StpUtil.isLogin();
        if (login) {
            Object userName = StpUtil.getExtra("userName");
            if (userName != null) {
                return userName.toString();
            }
        }
        return null;
    }

    @Override
    public String getLoginUserPhone() {
        boolean login = StpUtil.isLogin();
        if (login) {
            Object userPhone = StpUtil.getExtra("userPhone");
            if (userPhone != null) {
                return userPhone.toString();
            }
        }
        return null;
    }

    @Override
    public String getLoginUserRole() {
        boolean login = StpUtil.isLogin();
        if (login) {
            Object userPhone = StpUtil.getExtra("roleId");
            if (userPhone != null) {
                return userPhone.toString();
            }
        }
        return null;
    }
}
